package com.yike.user.service.impl;

import com.yike.user.entity.UserDetail;
import com.yike.user.mapper.UserDetailMapper;
import com.yike.user.service.UserDetailService;
import com.yike.user.param.UserDetailPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yike.common.base.BaseServiceImpl;
import com.yike.common.pagination.Paging;
import com.yike.common.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 后台用户详情表 服务实现类
 *
 * @author yike
 * @since 2024-07-17
 */
@Slf4j
@Service
public class UserDetailServiceImpl extends BaseServiceImpl<UserDetailMapper, UserDetail> implements UserDetailService {

    @Autowired
    private UserDetailMapper userDetailMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveUserDetail(UserDetail userDetail) throws Exception {
        return super.save(userDetail);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateUserDetail(UserDetail userDetail) throws Exception {
        return super.updateById(userDetail);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteUserDetail(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<UserDetail> getUserDetailPageList(UserDetailPageParam userDetailPageParam) throws Exception {
        Page<UserDetail> page = new PageInfo<>(userDetailPageParam, OrderItem.desc(getLambdaColumn(UserDetail::getCreateTime)));
        LambdaQueryWrapper<UserDetail> wrapper = new LambdaQueryWrapper<>();
        IPage<UserDetail> iPage = userDetailMapper.selectPage(page, wrapper);
        return new Paging<UserDetail>(iPage);
    }

}
